#include <QCoreApplication>
#include<QThread>
#include<QMutex>
#include<iostream>
#include<QObject>
#include<QDebug>
using namespace std;

class ticktetsaller:public QObject
{
public:
     ticktetsaller();
     ~ticktetsaller()
     {

     }

     void whosalltickets();
public:
    QMutex *mutex;
    int *tickets;
    QString seller_tickets;


};

ticktetsaller::ticktetsaller()
{
    QMutex *mutex=NULL;
    int *tickets=NULL;
}

void ticktetsaller::whosalltickets()
{
    while(*tickets>0)
    {
        mutex->lock();
        qDebug()<<seller_tickets<<" sell tickets "<<(*tickets)--;
        mutex->unlock();
    }

}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    int tickets1=20;
    QMutex mutexs;

    QThread thread1;
    ticktetsaller sell1;
    sell1.moveToThread(&thread1);

    sell1.seller_tickets="seller kitty";
    sell1.mutex=&mutexs;
    sell1.tickets=&tickets1;

    thread1.start();
    QObject::connect(&thread1,&QThread::started,&sell1,&ticktetsaller::whosalltickets);

    QThread thread2;
    ticktetsaller sell2;
    sell2.moveToThread(&thread2);

    sell2.seller_tickets="seller run";
    sell2.mutex=&mutexs;
    sell2.tickets=&tickets1;

    thread2.start();
    QObject::connect(&thread2,&QThread::started,&sell2,&ticktetsaller::whosalltickets);

    QThread thread3;
    ticktetsaller sell3;
    sell3.moveToThread(&thread3);

    sell3.seller_tickets="seller Son";
    sell3.mutex=&mutexs;
    sell3.tickets=&tickets1;

    thread3.start();
    QObject::connect(&thread3,&QThread::started,&sell1,&ticktetsaller::whosalltickets);



    return a.exec();
}
